package com.TIEmulator;

import android.content.Context;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.TextView;
import com.TIEmulator.JNI.NLib;
import java.util.ArrayList;
import java.util.Iterator;

public class OnScreenKeys
{
  private static final int ALPHA_KC = 1009;
  public static int APPS_KC = 0;
  private static final int BKSPACE_KC = 8;
  private static final int CATALOG_KC = 522;
  private static final int CLEAR_KC = 1005;
  private static final int DIAMOND_KC = 1008;
  private static final int DIVIDE_KC = 47;
  public static int DOWN_KC = 0;
  public static int ENTER_KC = 0;
  private static final int ESC_KC = 27;
  private static final int HOME_KC = 1002;
  private static final int INSERT_KC = 1001;
  public static int LEFT_KC = 0;
  private static final int MODE_KC = 1006;
  private static final int MULTIPLY_KC = 42;
  private static final int PCKEY_OEM_5_KC = 1004;
  public static int RIGHT_KC = 0;
  public static int SECOND_KC = 0;
  public static int SHIFT_KC = 0;
  private static final int SMALLMINUS_KC = 126;
  private static final int TAB_KC = 9;
  private static final int TAN_KC = 1003;
  private static final int TETA_KC = 1007;
  public static int UP_KC;
  private static OnEnter mOnEnterInterface;

  static
  {
    DOWN_KC = 504;
    LEFT_KC = 502;
    RIGHT_KC = 503;
    UP_KC = 501;
    ENTER_KC = 13;
  }

  public static void Setup(View paramView, Context paramContext)
  {
    1 local1;
    ArrayList localArrayList;
    int[] arrayOfInt1;
    int[] arrayOfInt2;
    Iterator localIterator1;
    if (paramContext instanceof OnEnter)
    {
      mOnEnterInterface = (OnEnter)paramContext;
      local1 = new View.OnTouchListener()
      {
        public boolean onTouch(View paramView, MotionEvent paramMotionEvent)
        {
          if (paramMotionEvent.getAction() == 0)
          {
            int j = paramView.getId();
            if (j > -1)
            {
              if (j == OnScreenKeys.ENTER_KC)
                OnScreenKeys.mOnEnterInterface.onEnterClicked();
              NLib.postTIKeyCodeIdx(j);
            }
          }
          for (int i = 1; ; i = 0)
            return i;
        }
      };
      localArrayList = paramView.getTouchables();
      int i = localArrayList.size();
      arrayOfInt1 = new int[i];
      arrayOfInt2 = new int[i];
      localIterator1 = localArrayList.iterator();
    }
    int[] arrayOfInt3;
    int i1;
    int i2;
    int i3;
    int i4;
    int i5;
    int i6;
    int i7;
    int i8;
    Iterator localIterator2;
    int i9;
    label119: int l;
    for (int j = 0; ; j = l)
    {
      if (!(localIterator1.hasNext()))
      {
        arrayOfInt3 = NLib.transcodeCodeIdx(arrayOfInt1, arrayOfInt1.length);
        i1 = -1;
        i2 = -1;
        i3 = -1;
        i4 = -1;
        i5 = -1;
        i6 = -1;
        i7 = -1;
        i8 = 0;
        localIterator2 = localArrayList.iterator();
        i9 = -1;
        if (localIterator2.hasNext())
          break;
        APPS_KC = i1;
        SECOND_KC = i2;
        SHIFT_KC = i3;
        DOWN_KC = i4;
        LEFT_KC = i5;
        RIGHT_KC = i6;
        UP_KC = i9;
        ENTER_KC = i7;
        paramView.setVisibility(4);
        while (true)
        {
          return;
          Log.e("OnScreenKeys:Setup", "cannot setup because context is no instance of \"OnEnter\" interface ");
        }
      }
      View localView = (View)localIterator1.next();
      int k = getIntermediateKeyCode(localView);
      arrayOfInt2[j] = k;
      l = j + 1;
      arrayOfInt1[j] = k;
      localView.setOnTouchListener(local1);
      localView.setFocusable(false);
      if (!(localView instanceof TextView))
        continue;
      TextView localTextView = (TextView)localView;
      localTextView.setTextColor(-1);
      localTextView.setHighlightColor(-65281);
      localTextView.setHintTextColor(-16776961);
    }
    ((View)localIterator2.next()).setId(arrayOfInt3[i8]);
    if (arrayOfInt2[i8] == APPS_KC)
      i1 = arrayOfInt3[i8];
    while (true)
    {
      ++i8;
      break label119:
      if (arrayOfInt2[i8] == SECOND_KC)
        i2 = arrayOfInt3[i8];
      if (arrayOfInt2[i8] == SHIFT_KC)
        i3 = arrayOfInt3[i8];
      if (arrayOfInt2[i8] == DOWN_KC)
        i4 = arrayOfInt3[i8];
      if (arrayOfInt2[i8] == LEFT_KC)
        i5 = arrayOfInt3[i8];
      if (arrayOfInt2[i8] == RIGHT_KC)
        i6 = arrayOfInt3[i8];
      if (arrayOfInt2[i8] == UP_KC)
        i9 = arrayOfInt3[i8];
      if (arrayOfInt2[i8] != ENTER_KC)
        continue;
      i7 = arrayOfInt3[i8];
    }
  }

  private static int getIntermediateKeyCode(View paramView)
  {
    CharSequence localCharSequence = null;
    if (paramView instanceof TextView)
      localCharSequence = ((TextView)paramView).getText();
    switch (paramView.getId())
    {
    case 2131296273:
    case 2131296274:
    case 2131296275:
    case 2131296276:
    case 2131296277:
    case 2131296278:
    case 2131296279:
    case 2131296280:
    case 2131296281:
    case 2131296282:
    case 2131296283:
    case 2131296289:
    case 2131296291:
    case 2131296292:
    case 2131296295:
    case 2131296296:
    case 2131296300:
    case 2131296304:
    case 2131296307:
    case 2131296308:
    default:
      if ((localCharSequence == null) || (localCharSequence.length() != 1))
        break label437;
    case 2131296267:
    case 2131296268:
    case 2131296269:
    case 2131296270:
    case 2131296310:
    case 2131296312:
    case 2131296311:
    case 2131296313:
    case 2131296309:
    case 2131296293:
    case 2131296294:
    case 2131296301:
    case 2131296290:
    case 2131296271:
    case 2131296305:
    case 2131296303:
    case 2131296285:
    case 2131296286:
    case 2131296284:
    case 2131296287:
    case 2131296297:
    case 2131296298:
    case 2131296299:
    case 2131296302:
    case 2131296306:
    case 2131296288:
    case 2131296272:
    }
    for (int i = localCharSequence.toString().toLowerCase().charAt(0); ; i = -1)
    {
      while (true)
      {
        return i;
        i = LEFT_KC;
        continue;
        i = UP_KC;
        continue;
        i = RIGHT_KC;
        continue;
        i = DOWN_KC;
        continue;
        i = 1001;
        continue;
        i = 1009;
        continue;
        i = 522;
        continue;
        i = 1002;
        continue;
        i = 1004;
        continue;
        i = 126;
        continue;
        i = 42;
        continue;
        i = 47;
        continue;
        i = 8;
        continue;
        i = ENTER_KC;
        continue;
        i = 1006;
        continue;
        i = APPS_KC;
        continue;
        i = 1007;
        continue;
        i = 1008;
        continue;
        i = SHIFT_KC;
        continue;
        i = SECOND_KC;
        continue;
        i = 1001;
        continue;
        i = 1002;
        continue;
        i = 1003;
        continue;
        i = 1004;
        continue;
        i = 1005;
        continue;
        i = 9;
        continue;
        i = 27;
      }
      label437: Log.e("OnScreenKeys:OnScreenKeys.getIntermediateKeyCode()", "unknown onscreen key detected!: Key View: " + paramView.toString());
    }
  }

  public static abstract interface OnEnter
  {
    public abstract void onEnterClicked();
  }
}
